@extends('admin.adminbase')
@section('content')


	<section class="hbox stretch">
		@include("admin.public.left")

		<aside>
			<section class="vbox">

				<header class="header bg-white b-b clearfix">
					<form class="talbe-search" method="get" action="">
						<div class="row m-t-sm">
							<div class="col-sm-12 m-b-xs">
								<div class="btn-group" role="group">
									<strong style="line-height:30px;">添加角色</strong>
								</div>
								<div class="btn-group pull-right">
									<a role="button" class="btn btn-info btn-sm " title="返回" onclick="history.back()">
										<i class="glyphicon glyphicon-arrow-left"></i>&nbsp;返回
									</a>
								</div>
							</div>
						</div>
					</form>
				</header>
				<section class="scrollable  wrapper w-f">
					<section class="panel panel-default ">
						<div class="row m-l-none m-r-none bg-light lter">
							<div class="container" style="padding: 20px 0px">
								<form class="form-horizontal" style="padding-top: 15px;" method="post" action="{{url("admin/role/create")}}">
									<input type="hidden" name="_method" value="PUT">
									{!! csrf_field() !!}
									<div class="form-group">
										<label class="col-sm-3 control-label">角色名<span class="red">*</span></label>
										<div class="col-sm-4 ">
											<input type="text" class="form-control" name="title" required="required" maxlength="20"
												   placeholder="请输入角色名">
										</div>
									</div>
									<div class="form-group">
                                        <label class="col-sm-3 control-label">节点<span class="red"></span></label>
                                        <div class="col-sm-9">
                                            @foreach($parentNode as $vo)
                                                <input type="hidden" id="box{$vo.id}" value="0"/>
                                                <div class="checkbox checkbox-primary check_item">
                                                    <input type="checkbox" name="node_id[]" data-id="{{$vo['id']}}" class="checkbox{{$vo['id']}} selAll" id="{{$vo['id']}}" value="{{$vo['id']}}"  checked/>
                                                    <label for="{{$vo['id']}}" style="padding-left: 0px"> {{$vo['title']}}</label>
                                                </div>
                                                <?php $search = DB::table('auth_nodes')->where('nid',$vo['id'])->get();?>
                                                @if($search)
                                                <div class="two_checkbox">
                                                    ┠─&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <?php foreach ($search as $item=>$val) {?>
                                                        <div class="checkbox checkbox-primary check_item" style="display:inline-block;margin-left:20px;margin-right: 10px;">
                                                            <input type="checkbox" name="node_id[]" class="checkbox{{$vo['id']}}" id="{{$val->id}}" value="{{$val->id}}" checked/>
                                                            <label for="{{$val->id}}" style="padding-left: 0px">{{$val->title}}</label>
                                                        </div>
                                                    <?php }?>
                                                </div>
                                                @endif
                                            @endforeach
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="control-label col-sm-3">状态<span class="red">*</span></label>
                                        <div class="col-sm-4">
                                            <input type="radio" id="status1" name="status" checked value="{{\App\Http\Util\Status::ON}}" checked>
                                            <label for="status1">启用</label>
                                            <input type="radio" id="status0" name="status" value="{{\App\Http\Util\Status::OFF}}">
                                            <label for="status0">禁用</label>
                                        </div>
                                    </div>
									<div class="form-group">
										<label class="col-sm-3 control-label"></label>
										<div class="col-sm-2 ">
											<button role="button" class="btn btn-default" addparm="" type="submit">提交</button>
										</div>
									</div>
								</form>
							</div>
						</div>

					</section>
				</section>
			</section>
		</aside>
	</section>
@endsection
@section('addscript')
	<script>
		$(function(){
             //操作父节点,子节点
             $("input:checkbox").on("click",function(){
                 var p_check = $(this).hasClass("selAll");
                 var isCheck = $(this)[0].checked;
                 //操作父节点
                 if(p_check && isCheck)
                 {
                     //子节点全选
                     var boxes = $(this).closest("div").next(".two_checkbox").find("input:checkbox");
                     boxes.each(function(){
                         $(this)[0].checked = true;
                     });
                 }
                 if(p_check && !isCheck)
                 {
                     //取消全选
                     var boxes = $(this).closest("div").next(".two_checkbox").find("input:checkbox");
                     boxes.each(function(){
                         $(this)[0].checked = false;
                     });
                 }

                 //操作子节点
                 if(p_check == false)
                 {

                     var boxes = $(this).closest(".two_checkbox").find("input:checkbox");
                     var allcheck = true;
                     var allnotcheck = true;
                     boxes.each(function(){
                         if($(this)[0].checked == false)
                         {
                             allcheck = false;
                         }
                         else
                         {
                             allnotcheck = false;
                         }
                     });

                     if(allcheck)
                     {
                         $(this).closest(".two_checkbox").prev(".check_item").find('input').prop('checked',true).trigger('change');
                     }
                    if(allnotcheck)
                    {
                        $(this).closest(".two_checkbox").prev(".check_item").find('input').prop('checked',false).trigger('change');
                    }
                 }
             });


		});
	</script>
@endsection
